﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BUS;
using DTO;


namespace GUI
{
    public partial class ThemKhachHang : Form
    {
        public ThemKhachHang()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txttenkh.Text == "")
            {
                MessageBox.Show("Vui lòng nhập tên khách hàng");
            }
            else
                ThemKH();
        }
        public void ThemKH()
        {
            try
            {
                KhachHangBUS khBUS = new KhachHangBUS();
                KhachHangDTO khDTO = new KhachHangDTO();
                khDTO.TenKhachHang = this.txttenkh.Text;
                khDTO.DienThoai = txtdienthoai.Text;
                khDTO.Email = txtemail.Text;
                khDTO.DiaChi = txtdiachi.Text;
                khDTO.CongTy = txtcongty.Text;

                string msg = khBUS.ThemKhachHang(khDTO);
                if (msg == "")
                {
                    MessageBox.Show("Thêm khách hàng thành công !");
                    this.Close();
                    PhieuDatCom fm = new PhieuDatCom();
                    fm.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi dữ liệu thêm khách hàng " + ex.Message);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ThemKhachHang_Load(object sender, EventArgs e)
        {
            this.ActiveControl = txttenkh;
        }
    }
}
